package notepad;

import java.awt.event.*;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;

import javax.swing.JFileChooser;

public class FileOpen implements ActionListener{

	public void actionPerformed(ActionEvent e) {
		JFileChooser chooser=new JFileChooser();
        int state=chooser.showOpenDialog(null);
        File file=chooser.getSelectedFile();
        String fileName = file.getName();
        Main.f=file;
        Main.title=fileName;
        if(file!=null&&state==JFileChooser.APPROVE_OPTION){
          try{  
        	  	Main.note1.setTitle(fileName);
        	  	ShowGUI.clearText();
         	 	BufferedReader bf= new BufferedReader(new FileReader(file));
  	 			String str;
		        while ((str = bf.readLine()) != null) {
		        	ShowGUI.text.append(str+"\n");
		        }
		        bf.close();
          } 
          catch(IOException e1){}
        }
	}
	
}